Given the following partial class, add the necessary constructor function so that both declarations within main() are valid. class samp { int a; public: //add constructor functions int get_a() {...

      

Given the following partial class, add the necessary constructor function so that both declarations within main() are valid.

class samp {
int a;
public:
//add constructor functions
int get_a() { return a;}
};
int main()
{
samp ob(88); //init ob's a to 88
samp obarray[10]; //nonitialized 10-element array
// ...
}

  

Answers


Davis

#include
using namespace std;
class samp {
int a;
public:
samp() { a = 0;}
samp(int n) { a = n;}
int get_a() { return a;}
};
int main()
{
samp ob(88);
samp obarray[10];
// ...
}
Githiari answered the question on May 31, 2018 at 18:03


Next: a)Show how to overload the constructor for the following class so that unitialized objects can also be created. (When creating uninitialized objects, give x and...
Previous: Given the following class definition, class test{ char *p; int *q; int count; public: test(char *x, int *y, int c) { p = x; q = y; count = c; } //... }; Is it possible...

View More Computer Studies Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions